﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataParser;

namespace argusThreeAndAHalfMen
{
    public partial class frmEditBranch : Form
    {
        //pointers
        private readonly Branch branch;
        private frmBranchDetails branchDetails;

        public frmEditBranch(Branch branch, frmBranchDetails branchDetails)
        {
            InitializeComponent();

            this.branch = branch;
            this.branchDetails = branchDetails;
        }

        //BTN SAVE CLICK EVENT
        private void btnSave_Click(object sender, EventArgs e)
        {//save all information from form objects into branch pointer
            string message = "Are you sure you wish to make these changes?";
            string caption = "Error Detected in Input";
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult result;

            // Displays the MessageBox.
            
            result = MessageBox.Show(message, caption, buttons);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                branch.Nickname = txtBranchName.Text;
                branch.StreetNumber = txtBranchHouseNameNumber.Text;
                branch.StreetName = txtBranchStreet.Text;
                branch.City = txtTownCity.Text;
                branch.County = txtCounty.Text;
                branch.Postcode = txtPostCode.Text;

                branchDetails.loadBranchDetails();
                Parser.SaveBranchList("argus-BIG.txt");

                // Closes the parent form.
                this.Close();
            }
        }

        //BTN CANCEL CLICK EVENT
        private void btnCancel_Click(object sender, EventArgs e)
        {//close form
            this.Close();
        }

        //FORM EDIT BRANCH LOAD EVENT
        private void frmEditBranch_Load(object sender, EventArgs e)
        {//sets all relevant information from branch pointer in form objects
            lblBranchID.Text = branch.BranchID.ToString();
            txtBranchName.Text = branch.Nickname;
            txtBranchHouseNameNumber.Text = branch.StreetNumber;
            txtBranchStreet.Text = branch.StreetName;
            txtTownCity.Text = branch.City;
            txtCounty.Text = branch.County;
            txtPostCode.Text = branch.Postcode;
        }
    }
}
